<template>
  <div class="calendar">
    <div class="calendar-header">
      <button class="nav-btn" @click="prevMonth">‹</button>
      <div class="month-year">
        {{ currentMonth }} {{ currentYear }} 🔥 4
      </div>
      <button class="nav-btn" @click="nextMonth">›</button>
    </div>
    <div class="weekdays">
      <span v-for="day in weekdays" :key="day">{{ day }}</span>
    </div>
    <div class="days">
      <span
        v-for="day in daysInMonth"
        :key="day"
        :class="{ today: isToday(day), special: isSpecial(day), streak: isStreak(day) }"
      >
        {{ day }}
      </span>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';

const date = ref(new Date());
const weekdays = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];

const currentMonth = computed(() => date.value.toLocaleString('default', { month: 'long' }));
const currentYear = computed(() => date.value.getFullYear());

const daysInMonth = computed(() => {
  const year = date.value.getFullYear();
  const month = date.value.getMonth();
  return Array.from({ length: new Date(year, month + 1, 0).getDate() }, (_, i) => i + 1);
});

const prevMonth = () => {
  date.value.setMonth(date.value.getMonth() - 1);
};

const nextMonth = () => {
  date.value.setMonth(date.value.getMonth() + 1);
};

const isToday = (day) => {
  const today = new Date();
  return (
    day === today.getDate() &&
    date.value.getMonth() === today.getMonth() &&
    date.value.getFullYear() === today.getFullYear()
  );
};

const isSpecial = (day) => {
  // Define special days here
  return [6, 7, 9].includes(day);
};

const isStreak = (day) => {
  return day >= 6 && day <= 9;
};
</script>

<style scoped>
.calendar {
  width: 100%;
  max-width: 400px;
  height: 350px;
  color: white;
  padding: 16px;
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.nav-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}

.month-year {
  font-size: 18px;
  font-weight: bold;
}

.weekdays {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.weekdays span {
  width: 14%;
  text-align: center;
  font-weight: bold;
}

.days {
  display: flex;
  flex-wrap: wrap;
}

.days span {
  width: 14%;
  text-align: center;
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 20%;
  transition: background-color 0.3s;
}

.days span.today {
  background-color: #ff5722;
  color: white;
}

.days span.special {
  background-color: #ff9800;
  color: white;
  position: relative;
}

/* .days span.special::after {
  content: '★';
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: #2196f3;
  color: white;
  padding: 2px;
  font-size: 10px;
} */

.days span.streak {
  background-color: #ff9800;
  color: white;
}
</style> 